package com.ming.springboot.data;

import lombok.Data;

/**
 * Created by mqsi on 2022/5/15 17:00
 */
@Data
public class Result<T> {
	private Integer status;
	private String desc;
	private T data;
	private String jwtToken;

	public String getJwtToken() {
		return jwtToken;
	}

	public void setJwtToken(String jwtToken) {
		this.jwtToken = jwtToken;
	}

	public static Result success(){
		Result result = new Result();
		result.setResultCode(ResultCode.SUCCESS);
		return result;
	}

	public static Result success(Object data){
		Result result = new Result();
		result.setResultCode(ResultCode.SUCCESS);
		result.setData(data);
		return result;
	}
	public static Result success(Integer status, String desc){
		Result result = new Result();
		result.setStatus(status);
		result.setDesc(desc);
		return result;
	}

	public static Result message(ResultCode resultCode){
		Result result = new Result();
		result.setResultCode(resultCode);
		result.setDesc(resultCode.getMessage());
		return result;
	}

	public static Result message(ResultCode resultCode, String desc){
		Result result = new Result();
		result.setResultCode(resultCode);
		result.setDesc(desc);
		return result;
	}

	public static Result fail(ResultCode resultCode){
		Result result = new Result();
		result.setResultCode(resultCode);
		return result;
	}

	public static Result fail(Integer status, String desc){
		Result result = new Result();
		result.setStatus(status);
		result.setDesc(desc);
		return result;
	}

	private void setResultCode(ResultCode resultCode){
		this.status = resultCode.getCode();
	}
}
